define(function(require, exports){
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var grid  = require('@base/highGrid');
	var util = require('util');
	var FILE_TYPE = pubjs.config('CONST/PTC/FIELD_TYPE');


	var Select = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'ptc/list',
					param: {
						'IsDeleted': 0
						,'Type': 2
						,'order' :'_id|-1'
						,'needAdx': true
						,'needField': true
					},
					cols: [
						{name: 'AdxName', text: LANG('渠道'), width: 80, align: 'center'},
						{name: "templateId", text:LANG('模板Id') , width: 60, align: 'center'},
						{name: "name", text:LANG('模板名称') , width: 200, align: 'center', render: 'renderName'},
						{name: "fields", text:LANG('素材要求') , width: 200, align: 'center', render: 'renderCond'}
					],
					hasSelect:true,		// 是否有多选列
					reqType: 'websocket',
					gridName: 'picText',
					subFilter: 'subFilter',
					hasAmount: false,
					hasTab: false,
					pager: {
						size: 10
					},
					hasExport: false
				}
			);

			if(util.exist(this.parseSubsCondition(config), 'whisky')){
				util.extend(true, config.get(), {
					'tab':{'cost': null, 'front': null}
				});
			}

			this.Super('init', arguments);
		}
		,renderName: function(i, val, data, conf)
		{
			var width = conf.width || 200;
			return `<div class="text-truncate" style="width: ${width}px;" title="${val}">
				${val}
			</div>`;
		}
		,renderCond: function(i, val, data, conf)
		{
			var width = conf.width || 200;
			var info = '';
			if(val && val.length)
			{
				var media = '';
				var text = '';
				util.each(val, function(item, i) {
					//info += i != 0 ? ';' : '';
					switch (item.type)
					{
						case FILE_TYPE.IMAGE:
							media += `${LANG('图片')}: ${item.width? item.width : LANG('不限')}${item.height ? ('*' +item.height) : ''},${LANG('描述')}:${item.description || LANG('无')};`;
							break;
						case FILE_TYPE.TEXT:
							//info += `${LANG('文字')}: 字数限制 > ${!item.min && !item.max ? LANG('不限') : (item.min + '-' + item.max)};`;
							text += `${LANG('文字')}: ${LANG('描述')}:${item.description || LANG('无')},长度：${!item.min && !item.max ? LANG('不限') : (item.min + '-' + item.max)};`;
							break;
						case FILE_TYPE.VIDEO:
							media += `${LANG('视频')}: ${item.width? item.width : LANG('不限')}${item.height ? ('*' +item.height) : ''},
							${LANG('描述')}:${item.description || LANG('无')}, ${LANG('时长')}: ${item.duration || LANG('不限')};`;
							break;
						default :
							break;
					}
				});
			}

			info = media + text;
			var div = `<div class="text-truncate" style="width: ${width}px;" title="${info}">
				${info}
			</div>`;

			return div;
		}
	});
	exports.selectTemplate = Select;

});